$(document).ready(function (){
require(['accordion','inputdrop','tree','wizard'],function (accordion ,inputdrop,tree,wizard){

var el_accordion = $("#accordion");

var list_current_type;

var list_current_data_name;

var current_selected_node_id;

var current_selected_node_name;

var paramObj = new Object();

view_init();

event_init();

$("#accordion_icon").find("div").eq(0).click();

function view_init()
{
	$("#accordion_icon").find("div").click(function (){
		list_current_data_name = $(this).attr("data-name");
		$("#accordion_icon").find("div").removeClass("active");
		$(this).addClass("active");
		tree_get();
    });
    
    index_list_search_render($("um-search") ,{
		cbf : function (val){
			g_grid.refresh($("#table_div") ,{
				paramObj : {monitorName : val}
			})
		},
		placeholder : "搜素手机号或姓名..."
	});
	g_formel.list_filter_render($("um-filter") ,{
		condition : [
						{text : "品牌" ,name : "currentStatus" ,data : [{text:"HTC",value:"1"} ,{text:"HUAWEI",value:"2"},{text:"ZTE",value:"2"},{text:"OPPO",value:"2"}]},
						{text : "管控域" ,name : "perfStatus" ,data : [{text:"一级管控域",value:"1"} ,{text:"二级管控域",value:"2"}]}
					],
		click : function (paramObj){
			g_grid.refresh($("#table_div") ,{
				paramObj : paramObj
			})
		}
	})

	$("#accordion").slimscroll()
}

function event_init()
{
	$("#candidate_asset_btn").click(function(){
		candidate_asset_tem_init();
	});
	$("#delete_btn").click(function(){
		selected_asset_list_batch_delete();
	});
	
}

function tree_get(currentNode)
{
	var self = this;
	var left_nav_tree_url;
	paramObj = {};
	if(list_current_data_name == "assetType")
	{
		left_nav_tree_url = "siem/logcollection/getAssertTree";
	}
	um_ajax_get({
		url : left_nav_tree_url,
		isLoad : true,
		successCallBack : function (data1){
			var data;
			if(list_current_data_name == "assetType")
			{
				data = data1;
				data.push({id:"root" ,parent:"-1" ,label:"全部"});
				current_selected_node_id = "105105";
			}
			if(currentNode)
			{
				current_selected_node_id = currentNode;
			}
			tree.render($("#accordion") ,{
				pId:"parentID",
				label:"label",
				id:"id",
				zNodes : data,
				expandNode : "root",
				selectNode : current_selected_node_id,
				zTreeOnClick : function (event, treeId, treeNode){
					current_selected_node_id = treeNode.id;
					current_selected_node_name = treeNode.label;
					if(list_current_data_name == "assetType")
					{
						paramObj.edTypeId = current_selected_node_id;
						if(treeNode.pId == "root")
						{
							g_dialog.operateAlert(null ,"请选择"+ treeNode.label+"下的组织单位。" ,"error");
							return false;
						}
					}
					else
					{
						paramObj.agentId = current_selected_node_id;
						// if(treeNode.pId == "root")
						// {
						// 	g_dialog.operateAlert($("[id=accordion]") ,"请选择"+ treeNode.label+"下的代理服务器。" ,"error");
						// 	return false;
						// }
					}
					if(treeNode.id == "root")
					{
						return false;
					}
					
					selected_asset_list_get({
						paramObj:paramObj,
						isLoad:true,
						maskObj:"body"
					});
				}
			});
			var treeObj = $("#accordion").data("tree").getSelectedNodes()[0];
			if (!treeObj)
				return
			current_selected_node_id = treeObj.id;
			current_selected_node_name = treeObj.label;
			if(list_current_data_name == "assetType")
			{
				paramObj.edTypeId = current_selected_node_id;
			}
			else
			{
				paramObj.agentId = current_selected_node_id;;
			}
			selected_asset_list_get({paramObj : paramObj ,isLoad : true ,maskObj : "body"});
		}
	});
}

function selected_asset_list_get(opt)
{
	var list_url;
	var header =  [	
		 		    {text:'',name:"t",width:3,hideSearch:"hide"},
				    {text:'终端型号',name:"edName",width:11,align:"left"},
				    {text:'终端品牌',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'手机号码',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'使用人',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'所属组织',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'管控域',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'事件数',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'执行指令',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }},
                    {text:'应用数',name:"ip",width:11,align:"left" ,searchRender:function (el){
						index_render_div(el ,{type:"ip"});
                    }}
				 ];;
	if(list_current_data_name == "assetType")
	{
		list_url = "siem/logcollection/queryByAssetList";//表格数据地址
	}
	
	g_grid.render($("#table_div1"),{
		 header:header,
		 oper:[
				  {icon:"rh-icon rh-edit" ,text:"修改" ,aclick:selected_asset_list_update},
				  {icon:"rh-icon rh-delete" ,text:"删除" ,aclick:selected_asset_list_delete}
			   ],
		 operWidth:"90px",
		 url:list_url,
		 paramObj : opt.paramObj,
		 queryBefore:function (paramObj){
			paramObj.assetname = paramObj.edName;
			paramObj.ip6 = paramObj.ipv6Str
			if (list_current_data_name == "assetType")
			{
				paramObj.edTypeId = current_selected_node_id;
			}
			else
			{
				paramObj.agentId = current_selected_node_id;
			}
		},
		 maskObj:opt.maskObj,
		 isLoad:opt.isLoad,
		 dbIndex:1,
		 hasBorder : false,
		 autoHeight : true,
         showCount : true,
        dbClick:function (rowData){
		 	monitor_info(rowData);
		 }
	});
}

function monitor_info(rowData)
{
	 window.location.hash="#/monitor_obj/terminal_List_detail?id="+rowData.sysId
}

function selected_asset_list_update(rowData)
{

}

function selected_asset_list_delete(rowData)
{
	
}




});
});